app.controller("ctrl2",["$scope","$http","$routeParams","goods","cart",
function($scope,$http,$routeParams,goods,cart){
	$scope.list=['热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果'];
    $scope.num=0;
    $scope.goods=goods;
    $scope.text=$routeParams.text;

	request();
	
	function request(){
        if(!$scope.goods[$scope.text]){
        	$http.get("http://h5.yztctech.net/api/axf/apicategory.php?category="+$scope.text)
		    .success(function(data){
			$scope.listData=data.data;
            $scope.goods[$scope.text]=data.data;
		    })
		    console.log($scope.goods);
        }
		
	}
	$scope.getData=function(text,index){
		$scope.num=index;
		$scope.text=text;
		request();
	}
	$scope.compute = function(item,num){
		if(item.num){
			item.num += num; 
		}else{
			item.num = 1;
		}
		
		if(item.num>0){
			cart.addCart($scope.text+item.id,item);
		}else{
			cart.dele($scope.text+item.id,item);
		}
	}
}]);